﻿CREATE TABLE [dbo].[Ordonantari] (
    [NrDoc]            DECIMAL (18)    NOT NULL,
    [DataDoc]          DATETIME        NOT NULL,
    [IDFurnizor]       BIGINT          NOT NULL,
    [ValoareLei]       DECIMAL (20, 2) NOT NULL,
    [IDJurnal]         INT             NOT NULL,
    [Scop]             VARCHAR (100)   NOT NULL,
    [DocJust]          VARCHAR (200)   NOT NULL,
    [AngLegal]         VARCHAR (50)    NOT NULL,
    [Achitat]          BIT             NOT NULL,
    [IdOrdonantare]    INT             IDENTITY (1, 1) NOT NULL,
    [CodUnitate]       SMALLINT        CONSTRAINT [DF_Ordonantari_CodUnitate] DEFAULT ((0)) NOT NULL,
    [IdModPlata]       INT             CONSTRAINT [DF_Ordonantari_IdModPlata] DEFAULT ((1)) NOT NULL,
    [TotalDatorat]     DECIMAL (18, 2) CONSTRAINT [DF_Ordonantari_TotalDatorat] DEFAULT ((0)) NOT NULL,
    [TotalAvansuri]    DECIMAL (18, 2) CONSTRAINT [DF_Ordonantari_TotalAvansuri] DEFAULT ((0)) NOT NULL,
    [ArtAl]            VARCHAR (40)    CONSTRAINT [DF_Ordonantari_ArtAl] DEFAULT ('') NOT NULL,
    [VizatCFP]         BIT             CONSTRAINT [DF_Ordonantari_VizatCFP] DEFAULT ((1)) NOT NULL,
    [MotivRefuz]       VARCHAR (250)   CONSTRAINT [DF_Ordonantari_MotivRefuz] DEFAULT ('') NOT NULL,
    [IDResponsabil]    INT             CONSTRAINT [DF_Ordonantari_IDResponsabil] DEFAULT ((0)) NOT NULL,
    [DataVizaCFP]      DATETIME        CONSTRAINT [DF_Ordonantari_DataVizaCFP] DEFAULT (getdate()) NOT NULL,
    [NrRegCFP]         VARCHAR (20)    CONSTRAINT [DF_Ordonantari_NrRegCFP] DEFAULT ('FARA') NOT NULL,
    [IBANSursa]        VARCHAR (24)    NULL,
    [IBANDest]         VARCHAR (24)    NULL,
    [IDDocumentPlata]  INT             NULL,
    [IDSursaFinantare] SMALLINT        NULL,
    CONSTRAINT [PK_Ordonantari] PRIMARY KEY CLUSTERED ([IdOrdonantare] ASC),
    CONSTRAINT [FK_Ordonantare_DocumentePlata] FOREIGN KEY ([IDDocumentPlata]) REFERENCES [dbo].[DocumentePlata] ([IDDocumentPlata]),
    CONSTRAINT [FK_Ordonantari_ArticoleAliniate] FOREIGN KEY ([ArtAl], [CodUnitate]) REFERENCES [dbo].[ArticoleAliniate] ([ArtAl], [CodUnitate]),
    CONSTRAINT [FK_Ordonantari_Furnizori] FOREIGN KEY ([IDFurnizor]) REFERENCES [dbo].[Parteneri] ([IDPartener]),
    CONSTRAINT [FK_Ordonantari_Jurnale] FOREIGN KEY ([IDJurnal]) REFERENCES [dbo].[Jurnale] ([IDJurnal]),
    CONSTRAINT [FK_Ordonantari_ModPlata] FOREIGN KEY ([IdModPlata]) REFERENCES [dbo].[ModPlata] ([IDModPlata]),
    CONSTRAINT [FK_Ordonantari_SurseFinantare] FOREIGN KEY ([IDSursaFinantare]) REFERENCES [dbo].[SurseFinantare] ([IDSursaFinantare]),
    CONSTRAINT [FK_Ordonantari_Unitati] FOREIGN KEY ([CodUnitate]) REFERENCES [dbo].[Unitati] ([CodUnitate])
);

